//Mesh, Animation and Light components

#pragma once
#include "ComponentsPrereq.h"
namespace ne{
class GameObject;
class MeshComponent : public Component,public IComponentObserver {
public:
	MeshComponent();
	virtual ~MeshComponent();

	void Init();
	void LoadMesh(const char* filename);
	void SetMaterial(const char* material);
	void Shut();
	void CreatePlane(const char* name,float width,float height,int xsegments,int ysegments);
	void DestroyPlane(const char* name);
	Ogre::Entity* GetEntity() const { return m_entity; }
	Ogre::SceneNode* GetSceneNode() const {return m_sceneNode;}
	virtual luabind::object GetAsLua(lua_State* L) {return luabind::object(L,this);}

	Ogre::Quaternion GetOrientation(){return m_sceneNode->getOrientation();}
	Ogre::Vector3 GetPosition(){return m_sceneNode->getPosition();}
	Ogre::Vector3 GetScale(){return m_sceneNode->getScale();}

	void SetScale(float x,float y,float z);
	void SetScale(const Ogre::Vector3& scale);
	void SetOrientation(const Ogre::Quaternion& quat){m_sceneNode->setOrientation(quat);}
	void SetOrientation(float w,float x,float y,float z){m_sceneNode->setOrientation(w,x,y,z);}

	void SetPosition(const Ogre::Vector3& pos){m_sceneNode->setPosition(pos);}
	void SetPosition(float x,float y,float z){m_sceneNode->setPosition(x,y,z);}
	void Translate(const Ogre::Vector3& v){m_sceneNode->translate(v);}
	void Translate(float x,float y,float z){m_sceneNode->translate(x,y,z);}
	void Yaw(float yaw){m_sceneNode->yaw(Ogre::Radian(yaw));}
	void Pitch(float pitch){m_sceneNode->pitch(Ogre::Radian(pitch));}
	void Roll(float roll){m_sceneNode->roll(Ogre::Radian(roll));}

	bool IsVisible();
	void SetVisible(bool value);
	void SetSkeletonBlendMode(int p_blendMode);
	void Notify(CEvent* evt);

protected:
	Ogre::SceneNode* m_sceneNode;
	Ogre::Entity* m_entity;
	Ogre::SceneManager* m_sceneManager;
};

class AnimationComponent : public Component,public IComponentUpdate,public IComponentObserver {
public:
	AnimationComponent();
	virtual ~AnimationComponent();
	void Update(GameTime* gameTime);
	void Init();
	void Shut();
	void PlayAnimation(const char* p_animId);
	void PauseAnimation(){m_isPlaying=(!m_isPlaying);}
	bool IsPaused()const{return m_isPlaying;}
	void StopAnimation();
	void Notify(CEvent* evt);
	
	luabind::object GetAsLua(lua_State* L) {return luabind::object(L,this);}

private:
	void GetOgreEntity();
	Ogre::AnimationState* m_animationState;
	Ogre::Entity* m_entity;
	bool m_isPlaying;
};

class LightComponent : public Component{
public:
	LightComponent();
	virtual ~LightComponent();

	void SetType(int type){m_light->setType((Ogre::Light::LightTypes)type);}
	void SetPosition(float x,float y,float z){m_light->setPosition(x,y,z);}
	void SetPosition(const Ogre::Vector3& vec3){m_light->setPosition(vec3);}
	void SetDirection(float x,float y,float z){m_light->setDirection(Ogre::Vector3(x,y,z).normalisedCopy());}
	void SetDirection(const Ogre::Vector3& vec3){m_light->setDirection(vec3.normalisedCopy());}
	void SetDiffuseColor(float r,float g,float b){m_light->setDiffuseColour(r,g,b);}
	void SetSpecularColor(float r,float g,float b){m_light->setSpecularColour(r,g,b);}
	void SetAttenuation(float range, float constant,float linear,float quadric){m_light->setAttenuation(range,constant,linear,quadric);}
	void Init();
	void Shut();
	Ogre::Light* GetLight() const {return m_light;}
	luabind::object GetAsLua(lua_State* L) {return luabind::object(L,this);}

protected:
	Ogre::SceneNode* m_sceneNode;
	Ogre::Light* m_light;
	Ogre::SceneManager* m_sceneManager;
};

} // namespace ne